/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Coordinador;

import InteracciónBD.DDBBAccess;
import InteracciónBD.Access;
import InteracciónBD.Conection;
import java.io.*;
import Diccionario_Interprete.Interpreter;

/**
 * Única Clase del Coordinador. Actua como una "UI".
 * @author Felipe Rachid - Javier Pérez
 */
public class Main
{
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        // TODO code application logic here
        try
        {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 
            DDBBAccess dbAccess = new DDBBAccess();
            Interpreter interpreter = new Interpreter();
            Conection conection = new Conection();
            int accessNumber = dbAccess.accessNumber();
            System.out.print("Please, introduce your SQL Query: ");
            String query = br.readLine();
            for(int i = 1; i <= accessNumber; i++)
            {
                Access access = dbAccess.obtainAccess(i);
                String translatedQuery = interpreter.translator(access.getName(), query);
                conection.openConnection(access.getLocation(), access.getUser(), access.getPass());
                String consola = access.getName().toUpperCase();
                System.out.println("\n\nGAMES OF " + consola + "\n\n");
                conection.obtainResultSet(translatedQuery);
                conection.printResultSet();
                conection.closeConcection();
            }
        }
        catch (Exception e) {System.err.println(e.toString());}
    }
}